package com.ali.juejin.ui.activity

import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.ali.juejin.R
import com.ali.juejin.adapter.HomeCategoryAdapter
import com.ali.juejin.base.BaseActivity
import com.ali.juejin.base.BaseApplication
import com.ali.juejin.model.CategoryModel
import com.blankj.utilcode.util.LogUtils
import kotlinx.android.synthetic.main.activity_category.*

class CategoryActivity: BaseActivity() {
    val model by lazy { ViewModelProvider(application as BaseApplication).get(CategoryModel::class.java) }
    val adapter by lazy { HomeCategoryAdapter(this,model) }
    override fun getLayoutId(): Int {
        return R.layout.activity_category
    }

    override fun initData() {
        if(model.homeFollowCategoryList.value.isNullOrEmpty()){
            model.getCategoryList()
        }
        model.homeFollowCategoryList.observe(this, Observer {
            value->
            value?.let {
                adapter.load(value)
            }
        })
    }

    override fun initView() {
        login_back.setOnClickListener {
            onBack()
        }
        category_list.layoutManager = LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)
        category_list.adapter = adapter
    }

}